package com.ht.module.bus.controller;

import com.ht.util.JsonResult;
import com.ht.util.Pager;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ht.module.bus.entity.BusRoomUser;
import com.ht.module.bus.service.BusRoomUserService;
import com.ht.util.*;



/**
 * <p>
 * 房间用户表 前端控制器
 * </p>
 *
 * @author hejialun
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/bus-room-user")
public class BusRoomUserController {

    
    @Autowired
    private BusRoomUserService busRoomUserService;


    @Operation(summary = "查询登录用户最近一次打开的房间")
    @GetMapping("/findLoginUserLatelyOpenRoom")
    public JsonResult findLoginUserLatelyOpenRoom(){
        return JsonResult.success(busRoomUserService.findLoginUserLatelyOpenRoom());
    }




    @Operation(summary = "查询指定房间用户")
    @GetMapping("/findRoomUser/{roomId}")
    public JsonResult findRoomUserByRoomId(@PathVariable(value = "roomId") Integer roomId){
        return JsonResult.success(busRoomUserService.findRoomUserByRoomId(roomId));
    }



	@Operation(summary = "分页查询")
    @GetMapping("/findPage")
    public JsonResult findPage(Pager<BusRoomUser> pager, BusRoomUser en){
        return JsonResult.success(busRoomUserService.page(pager));
    }



	@Operation(summary = "通过id查询")
    @GetMapping("/get-by-id/{id}")
    public JsonResult getById(@PathVariable(value = "id") String id){
        return JsonResult.success(busRoomUserService.getById(id));
    }

    @Operation(summary = "新增")
    @PostMapping("/add")
    public JsonResult add(@RequestBody @Valid BusRoomUser en){
	    CommMethod.beanCreate(en);
        busRoomUserService.save(en);
        return JsonResult.success();
    }

    @Operation(summary = "通过id删除")
    @DeleteMapping("/delete-by-id/{id}")
    public JsonResult delete(@PathVariable(value = "id") String id){
        busRoomUserService.removeById(id);
        return JsonResult.success();
    }

    @Operation(summary = "修改")
    @PutMapping("/update")
    public JsonResult updateById(@RequestBody @Valid BusRoomUser en){
	    CommMethod.beanUpdate(en);
        busRoomUserService.updateById(en);
        return JsonResult.success();
    }



}
